<template>
  <div class="container">
    <el-dialog
      title="预览文章"
      :visible="showDialog"
      @close="closeDialog"
      class="dialog"
    >
      <div class="title">
        <h2>{{ articleView.title }}</h2>
        <div>
          <span>{{ formatDate(articleView.createTime) }}</span>
          <span>{{ articleView.username }}</span>
          <span class="el-icon-view"></span>
          <span>{{ articleView.visits }}</span>
        </div>
      </div>
      <div class="content" v-html="articleView.articleBody">
      </div>
    </el-dialog>
  </div>
</template>

<script>
import dayjs from 'dayjs'
export default {
  props: {
    showDialog: {
      type: Boolean
    },
    articleView: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  methods: {
    // 关闭弹窗
    closeDialog () {
      this.$emit('close-dialog')
    },
    // 时间格式化
    formatDate (value, str = 'YYYY-MM-DD HH:mm:ss') {
      return dayjs(value).format(str)
    }
  }
}
</script>

<style scoped lang='scss'>
::v-deep .el-dialog {
  margin-top: 15vh;
  width: 800px;
}
.title {
  border-bottom: 1px dashed #ccc;
  padding-bottom: 10px;
  h2 {
    padding: 0;
    margin: 0;
  }
  span{
    margin-left: 10px;
    margin-top: 10px;
  }
}
.content{
  background: #f5f5f5;
  padding: 10px;
}
</style>
